/* 
 * File:   Resource.h
 * Author: EnviousCreep
 *
 * Created on March 26, 2010, 3:31 PM
 */

#ifndef _RESOURCE_H
#define	_RESOURCE_H
#include <cstdlib>


template <typename Type>
class Resource
{
public:

    Resource()
    {
        references = 0;
        important = false;
        rawData = NULL;
    }

    Resource(Type* inRes)
    {
        rawData = inRes;
        references = 0; //default value
        important = false; //default value
    }

    Resource(bool inImportant, Type* inRes)
    {
        important = inImportant;
        rawData = inRes;
        references = 0; //default value
    }

    ~Resource()
    {
        if (rawData != NULL)
            delete(rawData);
    }
    
    int GetReferences()
    {
        return references;
    }

    void SetImportant()
    {
        important = true;
    }

    void SetUnimportant()
    {
        important = false;
    }

    Type* GetRawData()
    {
        return rawData;
    }

    bool IsImportant()
    {
        return important;
    }

    void IncreaseReference()
    {
        references++;
    }

    void DecreaseReference()
    {
        if (references > 0)
            references--;
    }

private:
	/**
	 * The number of references this Resource has.
	 * Used by garbage collector.
	 */
    int references;
	
	/**
	  * Indicator used by garbage collector
	  */
    bool important;
	
	/**
	 * Pointer to the true data.
	 */
    Type* rawData;
};

#endif	/* _RESOURCE_H */

